/*
 * $Id: mtx.h,v 1.5 2005-12-23 16:33:43 bacon Exp $
 */

#ifndef _XP_BAS_MTX_H_
#define _XP_BAS_MTX_H_

#include <xp/types.h>
#include <xp/macros.h>
#include <xp/bas/thr.h>

#ifdef _WIN32
	typedef HANDLE xp_mtxhnd_t;
#else
	typedef pthread_mutex_t xp_mtxhnd_t;
#endif

/* 
 * TYPE: xp_mtx_t
 *   Defines a mutex object
 */
typedef struct xp_mtx_t xp_mtx_t;

struct xp_mtx_t
{
	xp_mtxhnd_t hnd;
	xp_bool_t __dynamic;
};

#ifdef __cplusplus
extern "C" {
#endif

/*
 * FUNCTION: xp_mtx_open
 *   Creates a mutex object
 */
xp_mtx_t* xp_mtx_open (xp_mtx_t* mtx);

/*
 * FUNCTION: xp_mtx_close
 *   Destroys a mutex object
 */
int xp_mtx_close (xp_mtx_t* mtx);

/*
 * FUNCTION: xp_mtx_lock
 */
int xp_mtx_lock (xp_mtx_t* mtx);

/*
 * FUNCTION: xp_mtx_unlock
 */
int xp_mtx_unlock (xp_mtx_t* mtx);

/*
 * FUNCTION: xp_mtx_trylock
 */
int xp_mtx_trylock (xp_mtx_t* mtx);

#ifdef __cplusplus
}
#endif

#endif
